package com.qf.controller;

import com.qf.pojo.DtsAdmin;
import com.qf.pojo.DtsComment;
import com.qf.service.AdminCommentService;
import com.qf.service.BrandService;
import com.qf.util.ResponseUtil;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/comment")
public class AdminCommentController {

    @Autowired
    AdminCommentService commentService;
    @Autowired
    BrandService brandService;

    @RequestMapping("/list")
    public Object getList(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                          @RequestParam(value = "limit",required = false,defaultValue = "3") Integer limit,
                          @RequestParam(value = "sort",required = false,defaultValue = "add_time") String sort,
                          @RequestParam(value = "order",required = false,defaultValue = "desc") String order,Integer valueId,Integer userId){

        Subject subject = SecurityUtils.getSubject();
        List<Integer> brandsId = null;
        if(subject.hasRole("品牌制造商")){
            DtsAdmin admin = (DtsAdmin)subject.getPrincipal();
            brandsId = brandService.findByAdminId(admin.getId());

        }


        Map<String,Object> data = commentService.findPage(page,limit,sort,order,valueId,userId,brandsId);

            return ResponseUtil.ok(data);


    }

    @PostMapping("/delete")
    public Object delete(@RequestBody DtsComment dtsComment){

        commentService.delete(dtsComment);
        return ResponseUtil.ok();
    }





















}
